//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "ia\fn_civilianWaypointCode.sqf"
#include <tmf_constants.h>
#include <tmf_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_leader","_units","_wps"];
DEFAULT_PARAM(_leader,0,objNull);
DEFAULT_PARAM(_units,1,[]);

// If the leader is alive, it means the group still has units, so it's worth continuing.
if (alive _leader) then {
	_wps = waypoints (group _leader);
	(group _leader) setBehaviour "SAFE";
	if (count _units <= 0) then { _units = units (group _leader); };
	{
	  if (vehicle _x == _x || {(driver (vehicle _x)) == _x}) then {
		  _x setUnitPosWeak "AUTO";
		  _x setUnitPos "AUTO";
		  _x doMove (wayPointPosition(_wps call FFUNC(arrayRandomVal)));
		  // Prevents the idiots from running...
		  _x setSpeedMode "LIMITED";
		  sleep 1;
		  _x setSpeedMode "LIMITED";
	  };
	} foreach _units;
};

TRACE("End");
TMFPROFILERSTOP;